<template>
  <dv-border-box-8 style="padding-top: 10px ">
    <dv-decoration-7 style="width:100%;height:30px;">销售统计</dv-decoration-7>
    <div id="SaleStatistics" style="width: 100%;height: 250px"></div>
  </dv-border-box-8>
</template>

<script>

export default {
  name: "SaleStatistics",
  data() {
    return {
      saleData: [],
    }
  },
  mounted() {
    this.initEchart();
  },
  methods: {
    getData() {
      return new Promise((resolve) => {
        // 静态销售数据
        resolve({
          dateList: ['周一', '周二', '周三', '周四', '周五', '周六', '周日'],
          numList: [120, 240, 160, 320, 280, 400, 380],    // 总销售额数据
          numList2: [80, 160, 140, 240, 200, 320, 300]     // 合同额数据
        });
      })
    },
    initEchart() {
      let data = this.getData()
      data.then(res => {
        // 使用静态数据
        let date = res.dateList
        let sold = res.numList
        let contractAmount = res.numList2

        let myChart = this.$echarts.init(document.getElementById('SaleStatistics'), 'dark');

        let option = {
          backgroundColor: '',
          tooltip: {
            trigger: 'axis' // 触发类型，可选值为 'item'、'axis'
          },
          legend: {
            data: ['总销售额', '合同额']
          },
          // 网格配置项
          grid: {
            left: '3%',
            right: '4%',
            bottom: '3%',
            containLabel: true // 包含刻度标签在内的网格区域
          },
          // 坐标轴配置项
          xAxis: {
            type: 'category',  // 坐标轴类型为分类轴
            boundaryGap: false, // 坐标轴刻度不包含在内的网格区域
            data: date // 坐标轴刻度标签
          },
          yAxis: {
            type: 'value',
            name: '销售额'
          },
          // 数据系列配置项
          series: [
            {
              name: '总销售额',
              type: 'line',
              smooth: true,
              tooltip: {
                valueFormatter: function (value) {
                  return value + ' 万';
                }
              },
              data: sold
            },
            {
              name: '合同额',
              type: 'line',
              smooth: true,
              tooltip: {
                valueFormatter: function (value) {
                  return value + ' 万';
                }
              },
              data: contractAmount
            }
          ]
        };

        option && myChart.setOption(option);
      })


    }
  }
}
</script>

<style scoped>

</style>
